package com.bc.web.controller.admin;

import com.fs.common.extend.FSController;
import com.fs.common.util.FSDate;
import com.bc.web.model.TransferQrcode;
import com.jfinal.aop.Before;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.tx.Tx;

public class TransferQrcodeController extends FSController{
	
	public void search(){
		Page<TransferQrcode> items = TransferQrcode.dao.search(super.getSearchCondition());
		setPageResultToRequest("items", items);
		render("basedata/updateAccount.html");
	}
	
	public void payment(){
		render("basedata/transferQrcodeList.html");
	}
	
	public void addPage(){
		render("basedata/transferQrcodeAdd.html");
	}
	
	public void updatePage(){
		TransferQrcode qrcode = TransferQrcode.dao.findById(getPara("id"));
		qrcode.setAmount(qrcode.getAmount()/100);
		setAttr("qrcode", qrcode);
		render("basedata/transferQrcodeUpdate.html");
	}
	
	@Before(Tx.class)
	public void add(){
		TransferQrcode qrcode = getModel(TransferQrcode.class,"qrcode");
		if(TransferQrcode.dao.selectByURL(qrcode.getQrcodeUrl()) != null){
			renderFail("URL已存在");
		}else {
			qrcode.setCreateTime(FSDate.getDateTime());
			qrcode.setAmount(qrcode.getAmount() * 100);
			qrcode.save();
			renderSuccess();
		}
	}
	
	@Before(Tx.class)
	public void update(){
		TransferQrcode qrcode = getModel(TransferQrcode.class,"qrcode");
		qrcode.setAmount(qrcode.getAmount() * 100);
		qrcode.update();
		renderSuccess();
	}
	
	@Before(Tx.class)
	public void delete(){
		TransferQrcode qrcode = TransferQrcode.dao.findById(getPara("id"));
		TransferQrcode.dao.deleteById(qrcode.getId());
		renderSuccess(false);
	}
	
}
